using UnityEngine;
using UnityEngine.Playables;

public class GameObjectPlayableBehaviour : PlayableBehaviour
{
    public GameObject target;
    public bool show;
    public bool revertOnEnd;
    public int effectId;
    protected bool m_startShow;
    protected bool m_currentState;

    public override void OnBehaviourPlay(Playable playable, FrameData info)
    {
        base.OnBehaviourPlay(playable, info);
        m_startShow = target.activeInHierarchy;
        if (effectId > 0)
        {
            EffectAgent.Instance.Play(effectId, target.transform.position,true);
            m_currentState = show;
            TimerAgent.Instance.DelyExecute(() =>
            {
                if (target)
                    target.SetActive(m_currentState);
            }, 0.5f);
        }
        else
        {
            target.SetActive(show);
        }
    }
    public override void OnBehaviourPause(Playable playable, FrameData info)
    {
        base.OnBehaviourPause(playable, info);
        if (revertOnEnd && target)
        {
            target.SetActive(m_startShow);
            m_currentState = m_startShow;
        }
    }
}